package com.MoveEat.Utils;

import org.osmdroid.ResourceProxy;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.SimpleLocationOverlay;

import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.view.MotionEvent;
import android.widget.Toast;

import com.MoveEat.R;

public class MySimpleLocationOverlay extends SimpleLocationOverlay
{

	private String	mAddress;
	private Context	mContext;

	@Override
	public boolean onSingleTapUp(MotionEvent e, MapView mapView)
	{
		AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
		builder.setMessage(R.string.open_navigation_app).setCancelable(false).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener()
		{
			public void onClick(DialogInterface dialog, int id)
			{
				Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + mAddress));
				try
				{
					mContext.startActivity(intent);
				}
				catch (ActivityNotFoundException ex)
				{
					Toast.makeText(mContext, "Google Maps is not installed", Toast.LENGTH_LONG).show();
				}
			}
		}).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener()
		{
			public void onClick(DialogInterface dialog, int id)
			{
				dialog.cancel();
			}
		});
		AlertDialog alert = builder.create();
		if (mapView.isEnabled())
		{
			alert.show();
			return true;
		}
		else
		{
			return false;
		}
	}

	public MySimpleLocationOverlay(Context ctx, ResourceProxy pResourceProxy)
	{
		super(ctx, pResourceProxy);
		// TODO Auto-generated constructor stub
	}

	public MySimpleLocationOverlay(Context ctx)
	{
		super(ctx);
	}

	public MySimpleLocationOverlay(Context ctx, ResourceProxy pResourceProxy, String address)
	{
		this(ctx, pResourceProxy);
		mAddress = address;
		mContext = ctx;
	}

}
